package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Activity;
import cn.wolfcode.domain.ActivityItem;
import cn.wolfcode.domain.Employee;
import cn.wolfcode.mapper.ActivityItemMapper;
import cn.wolfcode.service.IActivityItemService;
import cn.wolfcode.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ActivityItemServiceImpl implements IActivityItemService {

    @Autowired
    private ActivityItemMapper activityItemMapper;


    @Override
    public List<ActivityItem> selectByActivityItemId(Long activityItemId) {
        List<ActivityItem> list = activityItemMapper.selectByActivityItemId(activityItemId);
        return list;
    }

    @Override
    public String insetRelation(Long optionsRadios,Long activityId) {

        Employee currentUser = UserContext.getCurrentUser();

        //判断是否投过票
        Activity activity = activityItemMapper.checkVote(currentUser.getId(),activityId);
        //修改投票人数
        //插入投票关系表
        if (activity == null){
            activityItemMapper.updateVoteNum(optionsRadios);
            activityItemMapper.insetRelation(optionsRadios,currentUser.getId(),new Date());
            return "投票成功";
        }else {
            return "您已经投过票了";
        }
    }
}
